<?php

use Illuminate\Http\Request;

/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the "api" middleware group. Enjoy building your API!
|
*/

//Route::middleware('auth:api')->get('/user', function (Request $request) {
//    return $request->user();
//});

//api控制器的命名在App\Http\Controllers\Api，laravel默认只在App\Http\Controllers下查找，所以必须给出namespace
Route::namespace('Api')->prefix("v1")->middleware('cors')->group(function (){

    Route::post('/image/dish','ImgDetectController@dish');
    Route::post('/image/plant','ImgDetectController@plant');

    Route::middleware('user.guard')->group(function () {
        Route::post('/user', 'UserController@store');
        Route::post('/login', 'UserController@login');
        Route::middleware('api.refresh')->group(function () {
            Route::get('/user', 'UserController@index')->name('user.index');
            Route::get('/user/info', 'UserController@info')->name('user.info');
            Route::get('/user/{user}', 'UserController@show')->name('user.show');
            Route::get('/logout', 'UserController@logout')->name('user.logout');
        });
    });

    Route::middleware('admin.guard')->group(function (){
        Route::post('/admin','AdminController@store');
        Route::post('/admin/login','AdminController@login');
        Route::middleware('api.refresh')->group(function (){
            Route::get('/admin','AdminController@index')->name('admin.index');
            Route::get('/admin/info','AdminController@info')->name('admin.info');
            Route::get('/admin/{user}','AdminController@show')->name('admin.show');
            Route::get('/admin/logout','AdminController@logout')->name('admin.logout');
        });
    });












});
